# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: api\handlers\scan\__init__.py
import logging
from api.handlers import ResourceHandler
from settings_provider import settings
from server.http_responses.http_errors import Http409, InvalidAuth
from server.routers.api.auth import ApiScanAuth
from scanners.scan_app.scan_app_base import ScanningAppBase
from helpers.setup_types import is_setup_type_on_premise_worker
from helpers.licensing.features import BaseLicense

_logger = logging.getLogger("api.handlers.scan")


class ScanApiHandler(ResourceHandler):
    def __init__(self, scanning_app, scanning_app_handler, request_auth, **_):
        super().__init__()
        if scanning_app != scanning_app_handler.scanning_app:
            _logger.error(
                "invalid_scanning_app %s!=%s",
                scanning_app,
                scanning_app_handler.scanning_app,
            )
            raise Http409("invalid_scanning_app")
        self.app = scanning_app_handler
        if request_auth:
            if is_setup_type_on_premise_worker():
                self.settings_storage = settings.get("worker_settings_storage")
                api_key = self.settings_storage.get("api_key")
                if not self.settings_storage.get("master_endpoint"):
                    _logger.warning("InvalidAuth: no master set")
                    raise InvalidAuth()
                if api_key != request_auth.api_key:
                    _logger.warning("InvalidAuth: api_key mismatch")
                    raise InvalidAuth()
                else:
                    api_key = settings.get("scan_api_key")
                    print(api_key, request_auth.api_key)
                    if api_key != request_auth.api_key:
                        _logger.warning("InvalidAuth: api_key mismatch")
                        raise InvalidAuth()
                if is_setup_type_on_premise_worker():
                    self.license = BaseLicense.get_system_license()
